/*
 * Copyright (C) 2009 Christoph Caks
 *
 * This file is part of GLWAK.
 *
 * GLWAK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GLWAK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with GLWAK.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Context.cpp
 *
 *  Created on: 11.07.2009
 *      Author: Christoph Caks
 */

#include <cstdlib>

#include "Context.h"


namespace glwak {

Context::Context() :
	shareContext( 0 ) {
}

Context::Context( Context *_shareContext ) :
	shareContext( _shareContext ) {
}

Context::Context( Window *_window ) :
	shareContext( 0 ) {
	_window->setContext( this );
}

Context::~Context() {
}

void Context::setConfiguration( ContextConfiguration _configuration ) {
	this->configuration = _configuration;
}

////////////////////////////////////////////////////////////
/// Evaluate a pixel format configuration.
/// This functions can be used by implementations that have
/// several valid formats and want to get the best one
////////////////////////////////////////////////////////////
int Context::evaluateFormat( unsigned int bitsPerPixel, ContextConfiguration& configuration, int colorBits, int depthBits, int stencilBits, int antialiasing ) {
	return abs( static_cast<int>( bitsPerPixel							- colorBits ) )   +
           abs( static_cast<int>( configuration.getDepthBits()			- depthBits ) )   +
           abs( static_cast<int>( configuration.getStencilBits()		- stencilBits ) ) +
           abs( static_cast<int>( configuration.getAntialiasingLevel()	- antialiasing ) );
}

}
